package com.z.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.z.base.vo.PageVo;
import com.z.blog.entity.User;
import com.z.blog.mapper.UserMapper;
import com.z.blog.service.IUserService;
import com.z.utils.MD5Utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * 用户Service业务层处理
 *
 * @author z
 * @date 2022-09-02
 */
@Service
@Slf4j
public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements IUserService {


    /**
     * 查询用户
     * @param user 用户
     * @param pageVo
     * @return 用户 分页集合
     * */
    @Override
    public PageInfo<User> selectUserPage(User user, PageVo pageVo) {
        PageHelper.startPage(pageVo.getPage(), pageVo.getLimit());
        List<User> data = baseMapper.selectUserList(user);
        return new PageInfo<>(data);
    }

    @Override
    public User login(String username, String password) {
        User user = baseMapper.selectOne(new QueryWrapper<User>().eq("username", username).eq("password", MD5Utils.code(MD5Utils.code(password)+"+z")));
        if(user == null){
            log.info("查无此人");
            return null;
        }
        return user;
    }

}
